def maxProfit(prices):
    min_price = 10 ** 4
    max_profit = 0
    for price in prices:
        # 每次都是当天的价格-最小值
        max_profit = max(price - min_price, max_profit)
        # 随着时间推移，最小值价格变化
        min_price = min(price, min_price)
    return max_profit


print(maxProfit([5, 1, 2, 3, 4, 10]))
print(maxProfit([6, 5, 3, 1]))
